/*
 * Queue.java   1.0 2008/07/28
 *
 * Copyright 2008 Web & Zen Multimedia, All rights reserved.
 * Use is subject to license terms.
 */
package it.wzm.lightweightlog;

import java.util.*;

/**
 * This class represent the place where we want to store our Entry, by default a Queue is cumulable
 * which means we want to first store all entries then a {@link QueueDumper} is subsequently called
 * to, at given interval, empty and unload each stored Entry to registered Dumper
 * @author Leonardo Celati
 * @param <E> any extended Entry
 */
abstract class Queue<E extends Entry> implements Constant, Cumulable {
    
    /**
     * true if this Queue is cumulable, default to true
     */
    private boolean cumulable=true;
    
    /**
     * Default constructor
     */
    protected Queue(Properties p) {
        // deciding if this Queue is Cumulable or not
        // by looking at the interface implemented
        List l = Arrays.asList(this.getClass().getInterfaces());
    	//List<Class> l = Arrays.asList(this.getClass().getInterfaces());        
    	// then in the list look for what we want to found
        if (l.contains(NotCumulable.class)) {
            cumulable=false; // no way this Queue is not cumulable
        }
        // clean up few resources
        l=null;
    }
    
    /**
     * Inform us if this Queue is Cumulable or not. Default to true
     * @return true or false
     */
    protected final boolean isCumulable() {
        return cumulable;
    }
    
    /**
     * See if this cell is empty
     * @return true if it's empty, false if not
     */
    abstract boolean isEmpty();
    
    /**
     * Store the element into the Queue
     * @param e Any extended Entry
     * @return true if the element is correctly added to queue
     */
    abstract boolean push(E e);
    
    /**
     * Retrieve the actual size of this Queue
     * @return the size of this Queue
     */
    abstract int size();
    
}

